package com.pray.praymall.order.web;

import com.alipay.api.AlipayApiException;
import com.pray.praymall.order.config.AlipayTemplate;
import com.pray.praymall.order.service.OrderService;
import com.pray.praymall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * do something
 *
 * @author 魂悸魄
 * @date 2020/10/12 18:45
 */
@Controller
public class PayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    @Autowired
    private OrderService orderService;

    /**
     * 1、将支付页让浏览器进行展示
     * 2、支付成功以后，我们要跳到用户的订单列表页
     * @param orderSn
     * @return
     * @throws AlipayApiException
     */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = {"text/html"})
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.getOrderPay(orderSn);
        // 返回的是一个页面，将此页面交给浏览器就行了
        return alipayTemplate.pay(payVo);
    }
}
